<?php
	defined('_JEXEC') or die('Restricted access');
	$db = JFactory::getDBO();
	$query = "SELECT id FROM #__pr_category WHERE parent_id = 0";
	$db->setQuery($query);
	$arrCat = $db->loadResultArray();

	$query = "SELECT id, name, alias, parent_id FROM #__pr_category WHERE parent_id IN (".implode(',',$arrCat).") ORDER BY name ASC";
	$db->setQuery($query);
	$children = $db->loadObjectList();
	foreach($children as $child){
		$query = "SELECT alias FROM #__pr_category WHERE id = ".$child->parent_id;
		$db->setQuery($query);
		$parent = $db->loadObject();
		
		$child->parent_alias = $parent->alias;
	}
?>
<script language="javascript">
jQuery(document).ready(function(jQuery) {
   	submitSearchForm = function(){
		if((jQuery('#manufacturer').val() == "") && (jQuery('#keyword').val() == "")){
			jQuery('#alert').html('Indtast venligst søgning oplysninger');
            jQuery('#backoverlay').show();
			jQuery('#show_popup').show();
			jQuery('#f_focus').html('manufacturer');
			return false;	
		}
		jQuery('#searchForm').submit();
	}
});
</script>
<form name="searchForm" id="searchForm" method="get" action="index.php">
	<input type="hidden" name="option" value="com_ecommerce" />
    <input type="hidden" name="view" value="search" />
    <input type="hidden" name="Itemid" value="16" />
    <a id="header-search-group">Søg i varegruppe</a>
    <div id="header-search-group-wrapper">
        <ul>
        	<?php 
				foreach($children as $child){
				$child_link = "index.php?option=com_ecommerce&view=list&parent=".$child->parent_id.":".$child->parent_alias."&catid=".$child->id.":".$child->alias."&Itemid=16";
			?>
            <li><a href="<?php echo $child_link;?>"><?php echo $child->name;?></a></li>
            <?php }?>	
        </ul>
    </div>
    <input class="header-search-1" name="manufacturer" id="manufacturer" type="text" placeholder="Søg på producent" value="<?php echo $_GET['manufacturer']?>"/>
    <input class="header-search-2" name="keyword" id="keyword" type="text" placeholder="Søg på varenavn, varenr" value="<?php echo $_GET['keyword']?>" />
    <a id="header-search-button" title="Søg" onclick="submitSearchForm();">Søg</a>
</form>
<div class="clear"></div>